package com.wswy.wzcx.ui.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.wswy.wzcx.R;
import com.wswy.wzcx.model.pay.PayStyleModel;
import com.wswy.wzcx.module.pay.PayManager;
import com.wswy.wzcx.widget.PayLayout;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;

/**
 * Created by wangduheng26 on 2018/3/14.
 * wangduheng26@gmail.com
 */

public abstract class PayFragment extends ILoginFragment implements View.OnClickListener {
    public TextView tvPay;
    public TextView tvPayMuch;
    public LinearLayout llForm;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_fkdj, container, false);

      tvPay = inflate.findViewById(R.id.tv_pay);
      tvPayMuch = inflate.findViewById(R.id.tv_pay_much);
      llForm = inflate.findViewById(R.id.ll_form);

        Context context = inflate.getContext();
        createView(context,llForm);
        return inflate;
    }


    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        tvPay.setOnClickListener(this);
        tvPayMuch.setText(getString(R.string.str_fkdj_params, "0.00"));

    }


    protected abstract void createView(Context context, LinearLayout layout);


    protected int payStyle;
    protected String orderNo;


    //private PayLayout payView;

    protected View createPayStyleView(Context context, ViewGroup parent) {
//        View inflate1 = LayoutInflater.from(context).inflate(R.layout.pay_type_choose, parent, false);
//        inflate1.setOnClickListener(this);

        PayLayout payView = new PayLayout(context);

        payView.setSelectedCallback(new Function1<PayStyleModel, Unit>() {
            @Override
            public Unit invoke(PayStyleModel payStyleModel) {

                updatePayType(payStyleModel);

                return null;
            }
        });

        updatePayType(payView.getPayStyle());

        return payView;
    }


    @Override
    public void onClick(View v) {


//        if (v == payView && PayManager.canChoosePayType()){
//
//            new ChoosePayTypeDialog(v.getContext(),
//                PayManager.getPayStyleMode(payStyle),
//                new Function1<PayStyleModel, Unit>() {
//                    @Override
//                    public Unit invoke(PayStyleModel payStyleModel) {
//                        updatePayType(payStyleModel);
//                        return null;
//                    }
//                }).show();
//        }



    }



    private void updatePayType(PayStyleModel payStyleModel){
        if (payStyleModel != null){

            payStyle = payStyleModel.getCode();
        }
    }

    @Override
    public void setupPage() {

    }
}
